<?php

namespace App\Libs\Commons;

class MyMessage
{
    // 错误代码说明
    // 服务级错误（1为系统级错误、2服务级错误）	 服务模块代码	具体错误代码
    // 20101

    // 系统模块
    const RPC_SUCCESS = 1;
    const SUCCESS = 10000;
    const ERROR = 10001;
    const UNKNOWN_ERROR = 10002;
    const NOLOGIN = 10003;
    const PARAM_EMPTY = 10004;
    const PARAM_LOSE = 10005;


    const REQUEST_METHOD_NEED_POST = 10006;
    const API_VERSION_FAIL = 10007;
    const SYSTEM_CTL_NOT_FOUND = 10008;
    const SYSTEM_CTL_ACTION_NOT_FOUND = 10009;
    const SYSTEM_REQUEST_MUST_POST = 10010;
    const SYSTEM_MIDDLEWARE_SIGN_ERROR = 10011;
    const SYSTEM_MIDDLEWARE_PARAM_LOSE = 10012;
    const SYSTEM_STATUS_ERROR = 10013;
    const DATA_NOT_FOUND = 10014;
    const NOAUTH = 10015;
    const PARAM_VALIDATE_FAILED = 10016;

    // 业务通用
    const VERIFY_ERROR = 20900;
    const REPEAT_OPERATE = 20901;

    // 维修厂
    const FIX_ACCOUNT_NO_EXIST = 21000;


    //sso
    const SSO_PASSPORT_CONFIG_EMPTY	= 30000;
    const SSO_PASSPORT_AUTH_ERROR	= 30001;

    //事件
    const EVENT_NO_PERMISSION	= 40000;
	const MUTUAL_AIDS_IN_HESUN = 40001;
    const MUTUAL_AIDS_IN_HEJIA = 40002;
    const MUTUAL_AIDS_IN_YANSHOU = 40003;

    const XBY_SAVE_ERROR = 80006;

    /**
     * 错误码map
     *
     * @author zhe.wang
     */
    static private function maps()
    {
        $system = array(
            self::RPC_SUCCESS => 'rpc success',
            self::SUCCESS => 'success',
            self::ERROR => 'error',
            self::UNKNOWN_ERROR => 'unknown error',
            self::NOLOGIN => '请登录',
            self::PARAM_EMPTY => '参数为空',
            self::PARAM_LOSE => '参数丢失',
            self::PARAM_VALIDATE_FAILED => '参数验证失败',
            self::REQUEST_METHOD_NEED_POST => '请求方法必须为POST',
            self::API_VERSION_FAIL => 'API版本错误',
            self::SYSTEM_CTL_NOT_FOUND => '控制器未找到',
            self::SYSTEM_CTL_ACTION_NOT_FOUND => '方法未找到',
            self::SYSTEM_REQUEST_MUST_POST => '请求方法必须为POST',
            self::SYSTEM_MIDDLEWARE_PARAM_LOSE => '中间件处理参数丢失',
            self::SYSTEM_MIDDLEWARE_SIGN_ERROR => '中间件签名效验失败',
            self::SYSTEM_STATUS_ERROR => '状态异常',
            self::DATA_NOT_FOUND => '数据未找到',
            self::NOAUTH => '鉴权失败'
        );

        $pub = [
            self::VERIFY_ERROR => '验证码输入错误',
            self::REPEAT_OPERATE => '不可重复操作',
        ];

        $fix = [
            self::FIX_ACCOUNT_NO_EXIST => '此账号未绑定平台合作修理厂，暂不支持登录',
        ];

        $xby = [
            self::XBY_SAVE_ERROR => '问卷保存失败'
        ];

        $sso = [
            self::SSO_PASSPORT_CONFIG_EMPTY => 'sso passport配置为空',
            self::SSO_PASSPORT_AUTH_ERROR => 'sso passport认证失败'
        ];

        $mutual = [
        		self::EVENT_NO_PERMISSION => '事件无权限',
            self::MUTUAL_AIDS_IN_HESUN => "核损老师正在核损，请稍等",
            self::MUTUAL_AIDS_IN_HEJIA => "核价老师正在核价，请稍等",
            self::MUTUAL_AIDS_IN_YANSHOU => "验车老师正在验收，请稍等",
        ];
        return $system + $pub + $fix + $xby + $sso + $mutual;

    }

    /**
     * 获取消息
     *
     * @param int $code
     * @return string
     * @author zhe.wang
     */
    static public function getMessage($code = null)
    {
        if (!empty($code)) {
            $maps = self::maps();
            if (isset($maps[$code])) {
                return $maps[$code];
            }
        }
        return '';
    }
}
